/*
客户服务通信模式:服务端实现
1、初始化ros节点
2、创建服务器实例化对象
3、接收请求并处理请求
4、打印日志
*/

#include "ros/ros.h"
#include "plumbing_c_s/AddInts.h"

bool response_callback(plumbing_c_s::AddIntsRequest &requeset, plumbing_c_s::AddIntsResponse &response)
{
    int num1 = requeset.num1;
    int num2 = requeset.num2;
    ROS_INFO("解析获取到的两个数字:num1=%d,num2=%d.", num1, num2);
    int sum = num1 + num2;
    ROS_INFO("返回结果为:%d", sum);
    response.sum = sum;
    return true;
}

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, ""); //设置中文编码
    ros::init(argc, argv, "server");
    ros::NodeHandle nh = ros::NodeHandle();
    ros::ServiceServer server = nh.advertiseService("addInts", response_callback);
    ROS_INFO("服务端启动！");
    ros::spin(); //回头接收消息
    return 0;
}
